﻿using System;
using System.Globalization;
using System.Reflection;
using FluentNHibernate;

namespace NHibernate.Sidekick.Utils.MappingConventions
{
    /// <summary>
    /// Sets the foreign key names with the convention "Id_{ForeignTable}".
    /// </summary>
    public class ForeignKeyConvention : FluentNHibernate.Conventions.ForeignKeyConvention
    {
        /// <summary>
        /// Gets the name of the key.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="type">The <see cref="System.Type"/>.</param>
        /// <returns></returns>
        protected override string GetKeyName(Member property, System.Type type)
        {
            return property == null
                       ? string.Format(CultureInfo.InvariantCulture, "Id_{0}", type.Name)
                       : string.Format(CultureInfo.InvariantCulture,"Id_{0}", property.Name);
        }
    }
}